
class Animal{
    public String name;
    public int age;
static int a;

public Animal(){

}
public Animal(String name,int age){
    this.name = name;
    this.age = age;
    System.out.println("Animal::(String,int)");
}

static{
    System.out.println("Amimal::static{}");
}

    {
        System.out.println("Amimal::{}");
    }

//    public Animal eat(){
//        System.out.println(name+"吃饭");
//    }
public void eat(){
    System.out.println(name+"吃饭");
}

    public static void funcation(){
        //System.out.println(name+"hello");  静态方法里面不能用this,也不能用super
    }
}

class Dog extends Animal{
    //傻是狗的属性
    boolean silly;
    //String name = "hello";
//static int a;
//super.a = 120;
static{
        System.out.println("Dog::static{}");
    }

    {
        System.out.println("Dog::{}");
    }

    public Dog(){

    }

//    public Dog(String name, int age) {
//
//    }

    public Dog(String name, int age, boolean silly){
        //1.先帮助父类部分初始化
        super(name,age);
        this.silly = silly;
        System.out.println("Dog::(String,int,boolean)");
    }
    @Override
public void eat(){
    System.out.println(name+"正在吃狗粮");
}

    public void houseGuard(){
        System.out.println(name+"看家");
        super.name = "xiaohuang";
        System.out.println(super.name+"看家");//访问父类的name
        //注意super只是个关键字，不是父类的引用，因为我们在使用父类中的成员是我们是没有父类对象的
        //System.out.println(Animal.this.name+"看家"); error 没有父类对象，如何引用
        super.eat();
        //super.a = 10;  //不推荐静态成员用引用来调用
//         System.out.println(super.a);
    }
}


class Cat extends Animal{
    public Cat(String name,int age){
        //super必须放在第一行
        super(name,age);
    }
    public Cat(){
        //super和this一起使用
        super("mimi",12);
        //this("mimi",17);
    }

    static {
        System.out.println("Cat::static{}");
    }
    {
        System.out.println("Cat::{}");
    }
    public void catchMouse(){
        System.out.println(name+"抓老鼠");
    }

    @Override
    public void eat() {
        System.out.println(name+"吃猫粮");
    }
}
class Date{
    public String toString(){
        System.out.println("aaa");
        return "bbb";
    }
}


//class D extends Animal,Cat{} error java只能继承一个类


public class Test {
//向下转型
    public static void main(String[] args) {
        Animal animal = new Cat();
        Cat cat = (Cat)animal;
        //animal.catchMouse();  error animal这个父类中没有catchMouse这个方法
        Animal animal1 = new Dog();
        if(animal1 instanceof Cat) {
            Cat cat1 = (Cat) animal1;//不安全
            cat1.catchMouse();
        }
        cat.catchMouse();
    }






//方法传参的过程当中  也可以发生向上转型
    public static void funcation2(Animal animal){
        animal.eat();
    }

    public static void main2(String[] args) {
        Dog dog = new Dog("hello",10,false);
        funcation2(dog);
    }


    public static void main1(String[] args) {
////        Date date = new Date();
////        System.out.println(date);
//        Dog dog = new Dog("hello",10,false);
////        dog.houseGuard();
//        System.out.println("-----------------------------");
//        Cat cat = new Cat();
//        System.out.println("-----------------------------   ");
//        Dog dog1 = new Dog();
        Dog dog = new Dog("hello",10,false);
        //animal这个引用指向了dog对象
        //1.直接赋值
        Animal animal = dog;//向上转型
        //animal.silly = false;  error不能访问 原因是animal中没有这个属性
        animal.eat();//动态绑定
//        Cat cat = dog; error
        Animal animal1 = new Cat();
        animal1.eat();

    }



}
